Skip to content

Sanitize stored CI output / 清理存储的 CI 输出 - #5013

Merged
adibarra merged 10 commits into
mainfrom
feat/redact-stored-logs
Nov 25, 2026
Merged

adibarra merged 10 commits into
mainfrom
feat/redact-stored-logs

Conversation

@adibarra

@adibarra adibarra commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

CI jobs upload server logs, results, eval outputs and profile traces as GitHub artifacts, and some of them reach the public database. Those files can hold access tokens, passwords in URLs, public host IPs, Oracle VCN host names and email addresses. This PR runs python -m infx.results.redact over every file a job uploads, right before its first upload.

The rules are the same as the app's log-redaction.ts (merged in SemiAnalysisAI/InferenceX-app#1760), which sanitizes logs again at ingest. Both repositories test against one vectors file. inferencex-e2e/infx/tests/results/redaction_vectors.json is a byte-for-byte copy of the app's log-redaction.vectors.json (76 cases, same {"cases": [{name, input, output}]} schema, no conversion). No dependency is added. The module needs only the standard library, because it runs on the bare Python that result processing uses.

Replaced with ***REDACTED***

  • Tokens. hf_, ghp_/gho_/ghu_/ghs_/ghr_, github_pat_, AKIA…/ASIA…, xox?-, sk-, nvapi- and JWTs.
  • The value of Authorization: Bearer|Basic|Token …, and a bare Bearer followed by a long token.
  • Secret assignments such as HF_TOKEN=…, "OPENAI_API_KEY": "…" and \"MY_SECRET_TOKEN\":\"…\". Lower-case keys (hf_token=…) and flags (--hf-token …) count only when the value mixes letters and digits.
  • URL passwords (scheme://user:pass@), with any scheme case and with JSON-escaped :\/\/.
  • Public IPv4 and global IPv6 addresses, the subnet part of *.oraclevcn.com hosts (the node label stays), and email addresses.

Kept

  • Private, loopback, link-local and CGNAT addresses, and internal host names (.internal, .local, .lan, also in email-like user@host.internal).
  • Package versions. ==4.15.4.0, cudnn_cu13-9.20.0.48, pip's Requirement already satisfied: … (9.19.0.56) and the version column of pip list, conda list and torch's [conda] dump.
  • Placeholders ($VAR, <…>, None, numbers), ordinary settings (initial-cluster-token: etcd-cluster), q@k.transpose(…), pkg@1.2.3, scp-style remotes and a bare Bearer before a slash path like bearer src/auth/….

Tokens are also found right after an ANSI colour or cursor code (\x1b[0m, \x1b[2K), its escaped spellings (\x1b[, \u001b[, \033[) and an escaped \n, \r or \t. Matching is ASCII-only, so 密钥hf_… is caught. The app's removal of private repository names is not ported, because it needs the run's repository visibility, which the uploader does not have.

Where it runs. The benchmark, multi-node, SpeedBench AL, profile, CollectiveX and OperatorX jobs redact before uploading. Profile traces are now redacted before they are uploaded and before they are pushed to InferenceX-trace-storage. Files whose sha256 is recorded in a JSON *sha256 field are left alone so power audits still verify. Files are streamed in blocks of lines and come out exactly as if the whole file were redacted at once.

Parity with the app. The app's redactText (run with bun) and this module give identical output on every vector, on 350,000 fuzz cases, on 28,000 multi-line cases streamed in blocks of 1 to 64 bytes, and on a 55 MB synthetic log with colour codes, pip tables, URLs, IPs and emails (329,295 redactions). There is no difference.

Performance. Linear in input size. Python is 2 to 10 times slower than the app.

100 MB input Python, file Python, 10 MB App (bun)
Realistic log lines 6.6 s 0.66 s 2.9 s
Lines of 5,000 a.b.c… labels 3.8 s 0.39 s 0.37 s
Lines of de-ad-be-ef- repeats 4.2 s 0.42 s 0.73 s
One 100 MB line of x (198.51.100.7) 6.8 s 0.71 s 1.3 s

The staging callback also no longer falls back to a hard-coded Vercel URL. It now requires the STAGING_APP_URL repository variable, which is set.

Warning

Not covered.

  • The h3-results video bundle is uploaded unredacted. SHA256SUMS and the evidence digests seal every file in it, so redacting it after the fact would break video ingest. Covering it means redacting before the bundle is sealed, in video-generation/evaluator/srt_bundle.py.
  • Redaction fails open. If the step fails, or a file cannot be read, the upload still happens with the raw file and a ::warning::.
  • A profile trace written as one JSON line is held in memory whole while it is redacted.
  • Artifacts and backups uploaded before this PR keep their raw text.
Validation details
  • Vectors: all 76 pass, and redacting each expected output again changes nothing. The app's tests run the same file.
  • Parity harness (throwaway, under /tmp): redactText from InferenceX-app/packages/db/src/etl/log-redaction.ts under bun against redact_text and the file path of this module.
    • 152 vector texts (inputs and outputs): identical.
    • 350,000 fuzz cases built from tokens, escapes, Unicode spaces, ſ/K folds, emoji and separators: identical.
    • 28,000 multi-line cases, each also streamed with 1 to 64 byte blocks and a 2 to 24 character JSON context limit: 84,000 runs, identical. Breaking the cross-block JSON context, the email-hint redo or the context compaction makes 3,227, 6,326 and 403 of them differ.
    • 306 lines at the 1,024 code unit window, with emoji and accented filler: identical. Ignoring the line break before a block makes 12 differ.
    • 55 MB realistic log, as text, as a file and as .gz: byte-identical to the app.
    • The four 100 MB benchmark inputs and their 10 MB heads: byte-identical to the app.
  • New tests fail on the previous implementation (57 of 176 in test_redact.py, including the linearity test, which took 5.2 s).
AI model disclosure
  • Model/version: anthropic/claude-opus-5-5
  • Role: merged main, ported the app's rules and copied the shared vectors, wrote the streaming, parity and linearity tests, ran the parity and performance comparisons, extended redaction to profile traces, CollectiveX and OperatorX, and wrote this description.
PR checklist and change type

Type of Change

  • Bug fix
  • New feature
  • Configuration change
  • Documentation update
  • Other (please describe)

Checklist

  • I have completed the AI model disclosure and kept it current
  • I have tested my changes locally
  • I have updated documentation if necessary
  • If python -m infx.matrix.changed --base origin/main lists affected config keys, I have appended one new entry covering them to the physical end of inferencex-e2e/perf-changelog.yaml; if it lists none, I have added none. I have not edited historical entries
  • If this PR appends an inferencex-e2e/perf-changelog.yaml entry, it carries exactly one primary sweep label (a maintainer applies it on fork PRs): full-sweep-fail-fast (recommended), full-sweep-enabled, or non-canary-full-sweep-enabled. Optional modifiers all-evals, evals-only, agentx-fast, and evals-last require a primary label; evals-only and agentx-fast block reuse while applied.
  • Before merging via reuse, a maintainer with write access to the repository has commented /use <run_id> (or the legacy /reuse-sweep-run) on this PR. Do this only once there is a final full sweep that is all green with evals passing, since after this comment the primary sweep label will no longer automatically kick off new sweeps. Remove and re-add the primary sweep label to force a new sweep.
中文

CI 作业会把服务器日志、结果、评测输出和 profile trace 作为 GitHub artifact 上传,其中一部分会进入公开数据库。这些文件可能包含访问令牌、URL 中的密码、公网主机 IP、Oracle VCN 主机名和邮箱地址。本 PR 在每个作业首次上传之前,对它上传的所有文件运行 python -m infx.results.redact。

规则与 app 的 log-redaction.ts(已在 SemiAnalysisAI/InferenceX-app#1760 合并)完全一致,app 在摄取时还会再清理一次。两个仓库使用同一份测试向量,inferencex-e2e/infx/tests/results/redaction_vectors.json 是 app 中 log-redaction.vectors.json 的逐字节副本(76 个用例,格式相同,无需转换)。本 PR 不新增依赖,模块只使用标准库,因为它运行在结果处理所用的无依赖 Python 上。

替换为 ***REDACTED*** 的内容:各类访问令牌(hf_、GitHub、github_pat_、AKIA/ASIA、Slack、sk-、nvapi- 和 JWT),Authorization: Bearer|Basic|Token 的值和较长的独立 Bearer 令牌,HF_TOKEN=… 等密钥赋值(包括 JSON 转义写法,小写键和 --hf-token 等参数要求值同时含字母和数字),URL 密码(任意大小写协议和 JSON 转义的 :\/\/),公网 IPv4 与全局 IPv6 地址,*.oraclevcn.com 的子网部分(保留节点名),以及邮箱地址。

保留的内容:私有、回环、链路本地和 CGNAT 地址,内部主机名(.internal、.local、.lan,邮箱形式也保留),包版本号(==4.15.4.0、pip 的 Requirement already satisfied: … (9.19.0.56)、pip list/conda list 的版本列),占位符和普通配置,q@k.transpose(…)、pkg@1.2.3、scp 形式的远程地址,以及后接斜杠路径的独立 Bearer。紧跟在 ANSI 颜色或光标控制码、其转义写法(\x1b[、\u001b[、\033[)以及转义的 \n、\r、\t 之后的内容同样会被识别。匹配只按 ASCII 进行,因此 密钥hf_… 也能被识别。app 中删除私有仓库名称的规则没有移植,因为它需要仓库可见性信息,而上传端没有这项信息。

执行位置:benchmark、multi-node、SpeedBench AL、profile、CollectiveX 和 OperatorX 作业都会在上传前清理。profile trace 现在会在上传以及推送到 InferenceX-trace-storage 之前清理。若某文件的 sha256 被记录在 JSON 的 *sha256 字段中,则保持原样,以便功耗审计仍能校验。文件按行块流式处理,结果与一次性处理整个文件完全相同。

与 app 的一致性:用 bun 运行 app 的 redactText,与本模块在全部测试向量、35 万个模糊测试用例、2.8 万个按 1 到 64 字节分块流式处理的多行用例,以及一份 55 MB 的合成日志(含颜色码、pip 表格、URL、IP 和邮箱,共 329,295 处替换)上的输出完全相同,没有任何差异。

性能:耗时与输入大小成线性关系,Python 比 app 慢 2 到 10 倍。100 MB 输入下,真实风格日志 6.6 秒,5,000 个 a.b.c… 标签的长行 3.8 秒,de-ad-be-ef- 重复行 4.2 秒,单行 100 MB 的 x (198.51.100.7) 6.8 秒(app 分别为 2.9、0.37、0.73、1.3 秒)。10 MB 输入的耗时约为十分之一。

staging 回调不再回退到写死的 Vercel 地址,而是要求设置 STAGING_APP_URL 仓库变量(该变量已设置)。

未覆盖的部分:h3-results 视频结果包仍以原样上传,因为其中每个文件都由 SHA256SUMS 和证据摘要锁定,事后清理会导致视频摄取失败,要覆盖它需要在 video-generation/evaluator/srt_bundle.py 封包之前清理。清理失败时仍会上传原始文件并给出 ::warning::。单行 JSON 格式的 profile trace 在清理时会整体载入内存。本 PR 之前上传的 artifact 和备份保留原始文本。

验证:全部 76 个测试向量通过,对期望输出再次清理不会产生变化。并行比对、模糊测试和性能数据见上方的 Validation details。新增测试在旧实现上会失败(test_redact.py 中 176 个测试有 57 个失败,其中线性耗时测试用了 5.2 秒)。

AI 模型使用说明:anthropic/claude-opus-5-5,负责合并 main、移植 app 的规则并复制共享测试向量、编写流式处理、一致性和线性耗时测试、进行一致性和性能比对、将清理扩展到 profile trace、CollectiveX 和 OperatorX,并撰写本说明。

Run infx.results.redact on every file benchmark, multi-node, SpeedBench AL and
profile jobs upload, right before the first upload. IP addresses become
per-job HMAC tags that keep ports and distinct hosts, Oracle VCN domains keep
only the host label, and credentials become ***REDACTED***. Files whose sha256
a power manifest records are left unchanged.

Also require the STAGING_APP_URL repository variable instead of hardcoding the
staging site as a fallback.
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

inferencex-e2e/infx diff: +1348 -11

Generally most InferenceX submissions don't need to add changes to the infx package. On the off chance they do, generally the diff is small. Please prompt your agent to clean your PR to keep your diff to only necessary & minimal changes too. We have an increased code quality bar for changes to the infx package.

中文

大多数 InferenceX 提交通常不需要修改 infx 包。即使确实需要,改动通常也很小。请让你的 agent 清理 PR,使改动只包含必要且最小的内容。infx 包的改动有更高的代码质量要求。

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings marked 🟡 are optional suggestions and need no follow-up push.

Comment thread .github/workflows/benchmark-tmpl.yml Outdated
)
fi
if [[ "$SCENARIO_TYPE" == video-generation ]]; then
paths+=(h3-results)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Video sweeps whose bundle records the private service endpoint will fail reuse validation after merge, because redaction breaks the bundle's sealed checksums. The redactor rewrites files under h3-results, but it only collects guard digests from JSON *sha256 fields (redact.py:304). It never reads the bundle's SHA256SUMS or the manifest evidence map. Fix: redact the bundle before it is sealed in srt_bundle.py, or treat SHA256SUMS and evidence digests as guards. Either way, every file listed in SHA256SUMS must still match its recorded hash. [also at: .github/workflows/benchmark-tmpl.yml:403 - Video-generation jobs can now upload h3-results bundles whose sealed checksums no longer match, so native video reuse validation rejects them.]

Why this was flagged

For video-generation, benchmark-tmpl.yml:402 adds h3-results to the redaction paths. video-generation/evaluator/srt_bundle.py:330 copies each cell's baseline directory into the bundle. Its configuration.json stores "endpoint" (runner.py:738), built from SRT_SERVICE_*_IPS (infx/bench/video.py:71), which is usually a private IP that _ALWAYS_TAGGED always tags. That file's digest sits only in SHA256SUMS (srt_bundle.py:539-544) and in manifest evidence, keyed by path. _DIGEST_FIELD and _collect_digests (redact.py:297-305) only read keys ending in sha256 inside .json files, so nothing guards it and it is rewritten. validate_video_artifacts then recomputes every hash (video_artifacts.py:16-33) and raises "checksum mismatch or incomplete inventory". validate_reusable_sweep_artifacts.py:66 therefore rejects the video sweep, which passes on the base branch. Files that are guarded through cell sha256 references, such as run.json, are still uploaded unredacted with the endpoint IP.

Verification: Trigger: any video-generation job whose SRT video service publishes an IP address in SRT_SERVICE_<svc>_IPS. Redaction then rewrites a file inside the already-sealed h3-results bundle, and validation rejects the bundle. The only guard in redact.py is _DIGEST_FIELD (line 71). On the base branch the bundle was uploaded unmodified and validated.

Comment thread inferencex-e2e/infx/results/redact.py Outdated
r"\bsk-(?:ant-|proj-)?[A-Za-z0-9_-]{32,}",
)
)
_URL_PASSWORD = re.compile(r"(\b[a-z][a-z0-9+.-]*://[^\s:/@]+:)[^\s@/]+@", re.ASCII)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 (optional) Some URL passwords will still reach public artifacts unredacted, which goes against the PR's own user:pass@ promise. _URL_PASSWORD needs a non-empty username, so redis://:secret@ host is skipped. It also stops matching when the password contains /, which is common in base64 or AWS-style secrets. Fix: match a password of any characters except whitespace up to the last @ before the host, and allow an empty username. Also match uppercase schemes, or compile with re.IGNORECASE.

Why this was flagged

The trigger is a log line or JSON value with a connection URL. One example is redis://:p4ss@ 10.1.2.3:6379, the standard empty-user Redis/NATS token form. Another is postgres://svc:ab/Cd+ef@ db:5432, a password containing /. Both reach redact_text (redact.py:142). The user group [^\s:/@]+ needs at least one character, so the empty-user form never matches. The password group [^\s@/]+@ cannot cross a /, so the slash form never matches either. Only the host IP gets tagged and the full password is left in the uploaded artifact. The regex has no re.IGNORECASE, so a scheme like HTTPS://user:pw@ is also missed. This step runs right before uploads that any signed-in GitHub user can download. Reviewers and operators may now trust stored artifacts to be credential-free when these forms are not. No other credential pattern in _CREDENTIALS covers arbitrary passwords.

Verification: Trigger: a log or JSON value contains a connection URL with an empty username (redis://:pw@ host) or a raw / in the password. The user group [^\s:/@]+ at redact.py:44 needs at least one character, so nothing matches. The password stays in plain text. The base branch redacts nothing, so this is a coverage gap in the new safeguard, not a regression.

Comment on lines +331 to +334
try:
outcome = redact_file(path, key, digests)
except (OSError, EOFError, ValueError, tarfile.TarError, zlib.error) as error:
print(f"::warning::could not redact {path}: {error}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 (optional) On runners where containers write root-owned logs, unredacted IPs and credentials still get uploaded, and the only sign is a warning. On any OSError, main prints ::warning::could not redact, skips the file and returns 0 (redact.py:331-335). The always() upload steps then publish the original. Fix: make the redaction fail closed. Exit non-zero when any file cannot be redacted, and gate the uploads on that outcome, or delete or truncate files that cannot be rewritten. Missing paths must still be ignored.

Why this was flagged

This needs a runner whose job containers write files as root into the workspace. .claude/commands/clean-amd-mi355-runner-root-files.md:14-16 documents this on mi355x-amds for benchmark_logs/logs/slurm_job-*, and benchmark-tmpl.yml:196-200 only chowns before the run. _replace calls tempfile.mkstemp(dir=path.parent), which raises PermissionError when the directory is root-owned. Reading a root-only file raises the same way. main (redact.py:331-335) catches it as OSError, prints a warning, continues and returns 0, so the step succeeds. The if: always() uploads that follow (Upload server logs, power audit bundle, agentic raw results, eval results) then publish the original file with every IP and token intact. The workflow README says these files are redacted. Nothing alerts anyone beyond an annotation, so the leak the PR exists to prevent goes unnoticed.

Verification: Trigger: a listed artifact can't be rewritten, for example because the temp-file write fails (ENOSPC). redact.py main prints ::warning::could not redact {path}, continues, and ends with an unconditional return 0. The later uploads in benchmark-tmpl.yml are always()-gated. They publish the original file containing IPs and credentials. The base already uploaded everything unredacted.

Comment on lines +120 to +122
staging_site = os.environ.get("STAGING_APP_URL")
if not staging_site:
raise RuntimeError("STAGING_APP_URL must be set to the app's staging site origin")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 (optional) If STAGING_APP_URL is unset, /stage-results requesters get no PR comment at all, including the started and failed notices that never use the staging URL. main raises before report runs, for every callback type. Only chart_links (succeeded path, line 96) actually needs the origin. Fix: require the origin only where links are built, e.g. pass os.environ.get("STAGING_APP_URL") through and raise inside chart_links, so started and failed comments still post while success links stay fail-closed. The failure is otherwise only visible in a repository_dispatch run in this repo, which the PR requester does not watch.

Why this was flagged

The trigger is any stage-results-started or stage-results-completed repository_dispatch from the app while the repository variable is unset. That happens after merge until someone sets it; the PR asks for that before merging, but this checkout cannot confirm it. stage-results-callback.yml:33 then passes an empty string, and stage_results_callback.py:121-122 raises STAGING_APP_URL must be set to the app's staging site origin before report is called. On the base branch, the fallback origin let every callback post or PATCH the PR comment. Now the started notice (lines 89-94) and the failure notice (lines 110-113) are dropped too, although neither reads staging_site. The requester sees no progress and no failure message. The only signal is a failed run in this repo's Actions tab. Nothing guards this: no step checks the variable, and the error goes to stderr in that run only.

Verification: Trigger: a stage-results-started or stage-results-completed repository_dispatch arrives while the STAGING_APP_URL repository variable is unset. stage_results_callback.py main() raises before report(...) is ever called. So the "started" and "failed" comments are never posted either. On the base branch, the fallback origin meant every callback type posted.

@adibarra adibarra changed the title Redact IPs and credentials from stored CI artifacts / 对存储的 CI 产物中的 IP 和凭据进行脱敏 Sanitize stored CI output / 清理存储的 CI 输出 Nov 11, 2026
# Conflicts:
#	.github/workflows/benchmark-tmpl.yml
Port every rule of InferenceX-app's log-redaction.ts (#1760) to infx.results.redact with the
standard library only, so the bare result-tooling interpreter keeps working. Variable-length
lookbehinds become fixed-width alternations or bounded checks, classes match what JavaScript's
u and iu flags match, and the bounded repeats and line window mirror the app's.

Copy log-redaction.vectors.json byte for byte. Files are redacted in blocks of lines with the
same result as the whole text, including a JSON key on an earlier line and the app's email
hint. Redact profile traces before they are uploaded or pushed, and redact CollectiveX and
OperatorX shard output before upload.

将 InferenceX-app 的 log-redaction.ts(#1760)中的全部规则移植到 infx.results.redact,只使用标准库,
使无依赖的结果处理解释器继续可用。变长后行断言改写为定宽分支或有界检查,字符类与 JavaScript 的 u、iu 标志一致,
有界重复与行窗口也与 app 相同。逐字节复制 log-redaction.vectors.json。文件按行块清理,结果与整段文本相同,
包括上一行的 JSON 键和 app 的邮箱提示。profile trace 在上传和推送前清理,CollectiveX 与 OperatorX 的分片输出在上传前清理。
@adibarra
adibarra merged commit f49d58e into main Nov 25, 2026
13 checks passed
@adibarra
adibarra deleted the feat/redact-stored-logs branch November 25, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant